/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javase - T21
 * <p>Powered by webrx On 2021-12-27 14:52:09
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T21 {
    void work() {
        String tn = Thread.currentThread().getName();
        while (true) {
            try {
                System.out.println(tn);
                TimeUnit.SECONDS.sleep(1);
            } catch (Exception e) {
                //e.printStackTrace();
                System.out.println(tn + "被打断，线程完成");
                break;
            }
        }
    }

    public static void main(String[] args) {
        var t = new T21();

        var t1 = new Thread(t::work, "T1");
        t1.start();

        try {
            TimeUnit.SECONDS.sleep(5);
            t1.interrupt();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
